<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
	</head>

	<body style="padding: 0px;">
		<div class="easyui-layout" style="width:100%;height:600px;">
			<div data-options="region:'center'">
				<div>
					<table id="dg" style="width:100%"></table>
				</div>
			</div>
		</div>
		<div id="toolbar"></div>
	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/datagrid-cellediting.js"></script>
	<script type="text/javascript">
		var toolbarType = TOOLBAR_EDITOR;
		var content = ""; /*定义一个空的content*/
		content = AddToolBar(toolbarType);

		function editdata() {
			$.messager.confirm({
				title: '正在保存系统配置',
				msg: '是否确认',
				fn: function(r) {
					console.log
					if(r) {
                         updateData();
					}
				}
			});
		}
		$("#toolbar").append(content); /*在ID=toolbar的标记后面添加content中的内容*/
		var _url = RemoteLinkAddress + "/set/listall.do";
		$('#dg').datagrid({
			url: _url,
			toolbar: '#toolbar',
			height: 300,
			rownumbers: true,
			columns: [
				[{
					field: 'ID',
					title: 'id',
					width: '5%'
				}, {
					field: 'SETNAME',
					title: '名称',
					width: '10%',
					align: 'center',
				}, {
					field: 'SETVALUE1',
					title: '值1',
					width: '20%',
					align: 'center',
					editor: 'text'
				}, {
					field: 'SETVALUE2',
					title: '值2',
					width: '20%',
					align: 'center',
					editor: 'text'
				}, {
					field: 'SETVALUE3',
					title: '值3',
					width: '30%',
					align: 'center',
					editor: 'text'
				}]
			],
		});
		$('#dg').datagrid('enableCellEditing').datagrid('gotoCell', {
			index: 0,
			field: 'ID'
		});

		function updateData() {
			var rowData = $("#dg").datagrid("getChanges", "updated");
			if(rowData.length==0)
			{
				return ;
			}
			for(var i = 0; i < rowData.length; i++) {
				_url = RemoteLinkAddress + "/set/update.do";
				console.log(rowData[i]);
				$.post(_url, rowData[i],
					function(result) {
						if(result.msg == "success") {
							$.messager.alert({ // show error message
								title: '成功',
								msg: '配置修改成功'
							});
						} else {
							$.messager.alert({ // show error message
								title: '错误',
								msg: "配置修改失败"
							});
						}
					},
					'json');
			}
		}
	</script>

</html>